package com.ruoyi.web.controller.elasticSearch;

import com.ruoyi.data.es.domain.SensorData;
import com.ruoyi.data.es.service.SensorDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName ElasticSearchController
 * @Author Iven
 * @Description TODO
 * @Date 2020/12/4 0:53
 */
@RestController
@RequestMapping("/es")
@Api("es数据管理")
public class ElasticSearchController {

    @Autowired
    private SensorDataService service;

    @GetMapping("/list")
    @ApiOperation("获取全部")
    public  Page<SensorData> list()
    {
        return service.findAll();
    }

    @GetMapping("/{code}")
    @ApiOperation("获取传感器数据")
    public Page<SensorData> get(@PathVariable String code)
    {
        PageRequest pageable = PageRequest.of(0, 50);
        return service.findByCode(code,pageable);
    }
    @PostMapping()
    @ApiOperation("新增传感器数据")
    public void add(@RequestBody SensorData data)
    {
        service.save(data);
    }
}
